import React from 'react';
import { ts2Formatter, renderState } from 'utils';
import moment from 'moment';
import { actions } from 'mirrorx';
{/*
可配置化种类：

1、表格头部字段 
    1、列表页表格头部字段集合 mainTableColumn
    2、编辑页表格头部字段集合 childTableColumn

2、编辑框的字段
    1、编辑页 直接显示在页面的编辑字段 FormField
    2、编辑页 需要点击表格的增行弹框编辑的字段 FormTableField
    3. 列表页查询区域  searchField

3.表头部的按钮  headerButtonSets

4.表行尾部按钮  columnButtonSets
*/}

//表头信息

//字段属性

//基本信息

const FormDataHeader = [
    {
    enname: "title",
    zhname: "标题",
    type: "FormControl",
    edit: true,
    pattern:/^\S*$/,
    message: "不能有空格",
    required: true,
},
{
    enname: "billCode",
    zhname: "请假单号",
    type: "FormControl",
    hidepage:{0:true},
    edit: false,
    required: false,
},
{
    enname: "organizationId",
    codename: "organizationCode",
    showname: "organizationName",
    zhname: "隶属组织",
    refname: "organization",
    type: "RefComponent",
    param:{
        "AUTH_refdim":"organization","AUTH_refcod":"promoterLeave"
    },
    cascadeName: [
        {
            paramkey: "EQ_organization.id",
            childtype: "DataHeader",
            refKey: "refpk",
            dtoKey: "organizationId",
            offers: "departmentId",  //部门
            resetOffersFlag: true,
        },{
            paramkey: "EQ_organization.id",
            childtype: "DataHeader",
            refKey: "refpk",
            dtoKey: "organizationId",
            offers: "shopId",  //门店
            resetOffersFlag: true,
        }],
    edit: true,
    required: false,
},
{
    enname: "departmentId",
    codename: "departmentCode",
    showname: "departmentName",
    alias:"organizationId",
    zhname: "隶属部门",
    refname: "departmentRef",
    param: {
        EQ_enableState: "0",
    },
    type: "RefComponent",
    edit: true,
    required: false,
},
{
    enname: "shopId",
    codename: "shopCode",
    showname: "shopName",
    zhname: "隶属门店",
    alias:"organizationId",
    refname: "terminal",
    type: "RefComponent",
    edit: true,
    required: false,
},
{
    enname: "promoterId",
    codename: "promoterCode",
    showname: "promoterName",
    zhname: "请假人",
    type: "RefComponent",
    refname: "promoterstRef",
    edit: true,
    required: false,
},
{
    enname: "applyDate",
    zhname: "申请时间",
    type: "DatePicker",
    format: "YYYY-MM-DD",
    defaultValue:moment(),
    edit: true,
},
{
    enname: "leaveTypeId",
    codename: "leaveTypeCode",
    showname: "leaveTypeName",
    zhname: "请假类型",
    code: "LEAVE_TYPE",
    type: "Select",
    edit: true,
    required:true,
},
{
    enname: "startDate",
    zhname: "开始时间",
    type: "DatePicker",
    format: "YYYY-MM-DD",
    required:true,
    edit: true,
},
{
    enname: "endDate",
    zhname: "结束时间",
    disabledDate:"startDate",
    type: "DatePicker",
    format: "YYYY-MM-DD",
    required:true,
    edit: true,
},
{
    enname: "leaveDays",
    zhname: "请假天数",
    type: "InputNumber",
    precision:1,
    step:0.5,
    edit: true,
},
{
    enname: "causeDescription",
    zhname: "原因说明",
    type: "FormControl",
    pattern:/^\S*$/,
    message: "不能有空格",
    edit: true,
},
{
    enname: "remark",
    zhname: "备注",
    type: "FormControl",
    required: false,
    componentClass: "textarea",
    pattern:/^\S*$/,
    message: "不能有空格",
    edit:true,
},
]

const columnpromoterLeaveAttachments = [
    {
        title: "标题",
        dataIndex: "filename",
        key: "filename",
        detailwidth: 250,
    }, {
        title: "上传时间",
        dataIndex: "creationTime",
        key: "creationTime",
        detailwidth: 150,
        render: (text, record, index) => {
            return text && ts2Formatter(text,1);
        }
    }, {
        title: "缩略图",
        dataIndex: "fileUrl",
        key: "fileUrl",
        width: 150,
        render: (text, record, index) => {
            if(record.fileUrl.search("jpg") != -1 || record.fileUrl.search("jpeg") != -1 ||record.fileUrl.search("png") != -1){
                return <span>
                <img style={{"width":"35px"}} src={text} />
             </span>
            }else {
                return ""
            }
            
        }
    }, 
    {
        title: "创建人",
        dataIndex: "creator",
        key: "creator",
        width: 150,
    }
]


//表单字段

export const FormField = {
    "DataHeader": {
        "title": "基础信息",
        "Field": FormDataHeader
    },
}

//表格弹框表单字段
export const FormTableField = {
}

//渲染成字表表格的头
export const childTableColumn = {
    "promoterLeaveAttachments": {
        "title": "附件",
        "type": "grid",
        // "hidepage": { 0: true },
        "column": columnpromoterLeaveAttachments
    },
}

//渲染成字表表格的头
export const mainTableColumn = [
    {
        title: "标题",
        dataIndex: "title",
        width:110,
        key: "title",
    },
    {
        title: "请假单号",
        dataIndex: "billCode",
        key: "billCode",
        width:100,
        render: (text, record) => {
            return <a style={{ "cursor": "pointer" }}
                onClick={() => {
                    actions.routing.push(
                        {
                            pathname: 'PromoterLeaveApplication-edit',
                            search: `?search_id=${record.id}&btnPageFlag=2`,
                        }
                    );
                    // location.reload();
                }}
            >
                {text}
            </a >;
        }
    },
    {
        title: "隶属组织",
        dataIndex: "organizationName",
        width:100,
        key: "organizationName",
    },
    {
        title: "隶属门店",
        dataIndex: "shopName",
        width:100,
        key: "shopName",
    },
    {
        title: "审批状态",
        dataIndex: "state",
        width: 90,
        key: "state",
        render: (text, record, index) => {
            return renderState(text);
        }
    },
    {
        title: "隶属部门",
        dataIndex: "departmentName",
        key: "departmentName",
        width:100,
    },
    {
        title: "请假人",
        dataIndex: "promoterName",
        width: 100,
        key: "promoterName",
    },
    {
        title: "申请时间",
        dataIndex: "applyDate",
        width: 100,
        key: "applyDate",
        render:(text)=>{
            return text && ts2Formatter(text);
        }
    },
    {
        title: "请假类型",
        dataIndex: "leaveTypeName",
        width: 100,
        key: "leaveTypeName",
    },
    {
        title: "开始时间",
        dataIndex: "startDate",
        width: 100,
        key: "startDate",
        render:(text)=>{
            return text && ts2Formatter(text);
        }
    },
    {
        title: "结束时间",
        dataIndex: "endDate",
        width: 100,
        key: "endDate",
        render:(text)=>{
            return text && ts2Formatter(text);
        }
    },
    {
        title: "请假天数",
        dataIndex: "leaveDays",
        width: 100,
        key: "leaveDays",
    },
    {
        title: "原因说明",
        dataIndex: "causeDescription",
        width: 100,
        key: "causeDescription",
    },
    {
        title: "备注",
        dataIndex: "remark",
        key: "remark",
    }
]

export const searchField = [
    {
        enname: "title",
        zhname: "标题",
        type: "FormControl",
        searchType:"like",
        edit: true,
    },
    {
        enname: "billCode",
        zhname: "请假单号",
        type: "FormControl",
        searchType:"like",
        edit: true,
        required: false,
    },
    {
        enname: "organizationId",
        zhname: "隶属组织",
        refname: "organization",
        type: "RefComponent",
        param:{
            "AUTH_refdim":"organization","AUTH_refcod":"promoterLeave"
        },
        edit: true,
        required: false,
    },
    {
        enname: "departmentId",
        zhname: "隶属部门",
        refname: "departmentRef",
        type: "RefComponent",
        edit: true,
        required: false,
    },

    {
        enname: "shopId",
        zhname: "隶属门店",
        alias:"organizationId",
        refname: "terminal",
        type: "RefComponent",
        edit: true,
    },
    {
        enname: "promoterId",
        zhname: "请假人",
        type: "RefComponent",
        refname: "promoterstRef",
        edit: true,
        required: false,
    },
    {
        enname: "leaveTypeCode",
        zhname: "请假类型",
        code: "LEAVE_TYPE",
        type: "Select",
        edit: true,
    },
    {
        enname: "creationTime",
        zhname: "申请时间段",
        type: "RangePicker",
        rangeField:["creationTime","creationTime"],
        format: "YYYY-MM-DD",
        edit: true,
    },
    {
        enname: "applyDate",
        zhname: "请假时间段",
        type: "RangePicker",
        rangeField:["applyDate","applyDate"],
        format: "YYYY-MM-DD",
        edit: true,
    },
    
]

export const headerButtonSets = [
    {
        event: "ButtonAdd",
        zhname: "新增",
        color: 'primary',
        authcode: "Leaveadd",
    },
    // {
    //     event: "ButtonEnable",
    //     zhname: "启用",
    //     authcode: "9901-05-02-01",
    //     method: "post",
    //     batch: true,
    //     ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
    //     url: '/occ-base/base/promoter-leave/batch-enable'
    // },
    // {
    //     event: "ButtonEnable",
    //     zhname: "停用",
    //     authcode: "9901-05-02-01",
    //     method: "post",
    //     batch: true,
    //     ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
    //     url: '/occ-base/base/promoter-leave//batch-disable'
    // }
]

export const columnButtonSets = {
    "delete": {
        event: "ButtonDel",
        zhname: "删除",
        batch: true,
        method: "post",
        ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
        url: 'occ-base/base/promoter-leave/deleteByIds'
    },
    "edit": true,
    "detail": true
}

// export default {mainTableColumn,searchField,headerButtonSets,
//     columnButtonSets,childTableColumn,FormTableField,FormField}
export const SelectCode = ["LEAVE_TYPE","SZWD", "ZCLX", "PLAN_TYPE", "SALE_STATISTIC_BASIS", "COST_CALCULATION_TYPE", "URGENCY_DEGREE", "BILL_STATUS"]
